<h2 class="ico_settings">Listing Available Newsletter</h2>
<br/>
<table id="table">
    <tr >
        <th>Group</th>
        <th>Name</th>
        <th>Description</th>
        <th style="text-align: center">Action</th>
    </tr>

    {{if isset($letters)}}
          {{foreach from=$letters item=l}}
          <tr class="table_row" id="row-{{$l->id}}">
              {{assign var=group value=$l->get_letter_group()}}
              <td style="color:#AEA6A6">{{$group->name}}</td>
              <td>{{$l->name}}</td>
              <td>{{$l->description}}</td>
              <td align="center">
                  <button  onclick="document.location = '{{$base_index_url}}/newsl8r/admin/newsletter/update/{{$l->id}}'" >Edit</button>
                  <button onclick="delete_letter(this)" value="{{$l->id}}">Delete</button>
              </td>
          </tr>
          {{/foreach}}
    {{else}}
        <tr>
            <td colspan="4" align="center"> <h2>There are no letters..</h2>
                <a href="{{$base_index_url}}/newsl8r/admin/newsletter/create">create one??</a>
            </td>
        </tr>
    {{/if}}
</table>

<script>
    function delete_letter(self){
        var id = self.value;
        if(confirm('You sure you want to delete the newsletter?')){
            $.ajax({
                type:"POST",
                dataType:'text',
                data:"is_ajax=1&letter_id="+id,
                url: module_admin_url+"/newsletter/delete_letter",
                beforeSend: function(){
                     $.blockUI("<h1>Please wait...</h1>");
                },
                complete :  function(data){
                    $.unblockUI();
                    if(data.responseText!=="nok"){
                        var row_id = "#row-"+id;
                        $(row_id).fadeOut('slow');
                    }else{
                        alert("Could not delete the letter!");
                    }
                }
            });
        }
    }
</script>